package leetcode.code0973;

import java.util.PriorityQueue;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int[][] kClosest(int[][] points, int k) {
		PriorityQueue<long[]> queue = new PriorityQueue<>((a, b) -> Long.compare(b[0], a[0]));
		for (int i = 0; i < points.length; i++) {
			int[] cur = points[i];
			queue.add(new long[] { 1l * cur[0] * cur[0] + cur[1] * cur[1], 1l * i });
			if (queue.size() > k) {
				queue.poll();
			}
		}
		int[][] ans = new int[k][];
		int p = 0;
		while (!queue.isEmpty()) {
			ans[p++] = points[(int) queue.poll()[1]];
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
